﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace UCL.Powersource.TFS
{
    internal class TfsTeamProjectCollectionAdapter : ITfsTeamProjectCollection
    {
        internal TfsTeamProjectCollection TfsTeamProjectCollection { get; private set; }

        internal TfsTeamProjectCollectionAdapter(TfsTeamProjectCollection TfsTeamProjectCollection)
        {
            this.TfsTeamProjectCollection = TfsTeamProjectCollection;
        }

        public T GetService<T>()
        {
            return TfsTeamProjectCollection.GetService<T>();
        }

        public string Name
        {
            get
            {
                var r = TfsTeamProjectCollection.Name;
                if (r == null) return null;
                var allNames = r.Split('/','\\');
                //var allNamesForBS = allNames.LastOrDefault();
                //if (allNamesForBS != null)
                //{
                //    allNames = allNamesForBS.Split('\\');
                //}

                return allNames.LastOrDefault();
            }
        }

        public Uri Uri
        {
            get { return TfsTeamProjectCollection.Uri; }
        }

        public Project GetProject(string Name)
        {
            return TfsTeamProjectCollection.GetProject(Name);
        }

        public Project GetProjectAtIndex(int index)
        {
            return TfsTeamProjectCollection.GetProjectAtIndex(index);
        }
    }
}
